package com.defangit.award.extend.wxmp.config;

import com.defangit.award.domain.WinningInfo;
import com.defangit.award.extend.wxmp.domain.AwardUser;
import com.defangit.award.extend.wxmp.domain.WxmpUser;
import com.defangit.award.extend.wxmp.orm.WxmpUserService;
import com.defangit.award.orm.HibernateUtil;
import com.defangit.award.orm.WinningInfoService;
import com.defangit.openapis.wechat.mp.message.req.RequestMessage;
import com.defangit.openapis.wechat.mp.message.req.TextMessage;
import com.defangit.openapis.wechat.mp.message.req.event.ScanEvent;
import com.defangit.openapis.wechat.mp.message.req.event.SubscibeEvent;
import com.defangit.openapis.wechat.mp.message.req.event.UnSubscribeEvent;
import com.defangit.openapis.wechat.mp.message.resp.ResponseMessage;
import com.defangit.openapis.wechat.mp.message.resp.TextResponse;
import com.defangit.openapis.wechat.mp.user.domain.UserInfo;
import laogen.util.StringUtil;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.Subqueries;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by zhangfagen on 2019/1/22.
 */
public class GoldWxmpConfig extends AwardWxmpConfig{
    @Override
    public ResponseMessage handleMsg(RequestMessage msg) {

        ResponseMessage res=null;
        if (msg instanceof TextMessage) {
            res=awardByKey(msg.getFromUserName(),((TextMessage) msg).getContent());
        }

        if (msg instanceof ScanEvent) {//如果用户发送的信息是微信扫码事件
            try {
                String key=((ScanEvent) msg).getEventKey();
                res=awardByKey(msg.getFromUserName(),key);
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }
        if (msg instanceof SubscibeEvent) {
            if(StringUtil.notEmpty(((SubscibeEvent) msg).getEventKey())){
                try {
                    String key=((SubscibeEvent) msg).getEventKey();
                    res=awardByKey(msg.getFromUserName(),key);
                } catch (Exception ex) {
                    System.out.println(ex);
                }
            }else{
                res=new TextResponse()
                        .setContent("感谢您关注!");
            }
        }
        if(res==null){
            res=new TextResponse()
                    .setContent("sorry,没搞懂您想要什么");
        }
        return res;
    }

    public GoldWxmpConfig() {
        super("gold");
        setAppId("").setSecret("").setToken("");
    }


}
